package dao

import javax.inject.{Inject, Singleton}
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.ExecutionContext.Implicits.global

/**
 * Created by yz on 2018/5/29
 */
@Singleton
class PancancerIndexDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def deleteAll = db.run(GtexIndex.delete).map(_ => ())

  def insertAll(rows: List[PancancerIndexRow]) = db.run(PancancerIndex ++= rows).map(_ => ())

  def select(location: String) = db.run(GtexIndex.filter(_.location === location).map(_.index).
    result.headOption)

  def selectAll(location: String) = db.run(PancancerIndex.
    filter(_.location === location).result)

  def selectAll(location: String, kinds: List[String]) = db.
    run(PancancerIndex.filter(_.location === location).filter(_.kind.inSetBind(kinds)).result)

  def selectAll(location: String, kind: String) = db.
    run(PancancerIndex.filter(_.location === location).filter(_.kind === kind).result)

  def selectAllKind(location: String) = db.run(PancancerIndex.
    filter(_.location === location).map(_.kind).result)


}
